﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XCommunity.Views;

namespace XCommunity.Forums.Views
{

  /// <summary>
  /// 定义用于辅助呈现导航栏的视图对象
  /// </summary>
  public class NavigatorView : ViewObject
  {

    public NavigatorView( ForumsViewService service, string route )
      : base( service )
    {
      Route = route;
    }


    /// <summary>
    /// 获取路径
    /// </summary>
    protected string Route
    {
      get;
      private set;
    }


    /// <summary>
    /// 获取导航的每一个路径项
    /// </summary>
    /// <returns></returns>
    public NavigatorRouteItem[] GetRouteItems()
    {
      var nodes = Route.Split( '/' );


      return Enumerable.Range( 1, nodes.Length )
        .Select( count => string.Join( "/", nodes.Take( count ).ToArray() ) )
        .Select( route =>
          new NavigatorRouteItem()
          {
            Route = route,
            Title = ( (ForumsViewService) Service ).GetTitle( route )
          }
        ).ToArray();

    }


    /// <summary>
    /// 获取当前导航路径需要呈现的标题
    /// </summary>
    public string Title
    {
      get { return ( (ForumsViewService) Service ).GetTitle( Route ); }
    }


    /// <summary>
    /// 定义导航路径项
    /// </summary>
    public class NavigatorRouteItem
    {

      public string Route
      {
        get;
        set;
      }

      public string Title
      {
        get;
        set;
      }


    }


    public override object BaseObject
    {
      get { return Route; }
    }

  }
}
